	/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T12A_ITT_parentalpractices.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	local child "zptevir_irtscore2 zcog_index zsoc_index" 

	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	

/*******************************************************************************
	Table A12: IV Number of sessions attended parental outcomes
*******************************************************************************/

	local parental "zfbeh_gsem zfbel_gsem zfwb" 
	#delimit;
	foreach var of local parental {;
				
					
				* PANEL 3: ITT with Age and Gender and SES;
					xi: xtivreg `var' $Xvar1 (n_ses_b n_ses_i=group2 group3) if x==1,  fe i(CENTRO_SALUD);
					estimates store `var'_iv1;
					
				* PANEL 4: ITT plus parental characteristics -; 	  
					xi: xtivreg `var' $Xvar2 $parent_cha4 (n_ses_b n_ses_i=group2 group3) if x==1,  fe i(CENTRO_SALUD);
					estimates store `var'_iv2;
					
	};
		#delimit cr

		
	local itt "iv1 iv2"
	foreach x of local itt {
		
			esttab zfbeh_gsem_`x'  zfbel_gsem_`x' zfwb_`x' using "${tables}parental`x'_nsessions.csv", replace f ///	   
			keep(n_ses_b n_ses_i) ///
			cells("b(fmt(3)star)" "se(fmt(3)par)") ///
			star(* 0.10 ** 0.05 *** 0.01) ///
			stats(r2 N, fmt(2 0) labels("R-squared" "Observations")) legend								
	}
	
	
	
		***  Tables ITT Outcomes

	esttab zfbeh_gsem_iv1 zfbel_gsem_iv1   zfwb_iv1                   /*
		*/ using "${out_tables}/appendix/T12A_numbersessions_parental.csv", replace f		  /* 
		*/ keep(n_ses_b n_ses_i) 											  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2_o N, fmt(2 0) labels("R-squared" "Observations")) legend  /*
		*/ mtitles("Behavioral Index""Beliefs Index""Well-being Index" ) /*
		*/ title("IV with Age and Gender ") 	varlabels(n_ses_b "NEP-B" n_ses_i "NEP-I")

	esttab zfbeh_gsem_iv2 zfbel_gsem_iv2   zfwb_iv2        					  /*
		*/ using "${out_tables}/appendix/T12A_numbersessions_parental.csv", append f		  /* 
		*/ keep(n_ses_b n_ses_i) 											  /*
		*/ cells("b(fmt(3)star)" "se(fmt(3)par)") 							  /*
		*/ star(* 0.10 ** 0.05 *** 0.01) 									  /*
		*/ stats(r2_o N, fmt(2 0) labels("R-squared" "Observations")) legend  /*
		*/ mtitles("Behavioral Index""Beliefs Index""Well-being Index" ) /*
		*/ title("IV plus parental characteristics") 	varlabels(n_ses_b  "NEP-B" n_ses_i "NEP-I")
		
		
* End of dofile 

	
